package com.bgs.controller;

import com.bgs.entity.Commodityorder;
import com.bgs.pojo.BaseTest;
import com.bgs.pojo.CommodityorderVo;
import com.bgs.service.LjpexclusiveService;
import com.bgs.tool.AliOss;
import com.bgs.tool.R;
import org.apache.http.entity.ContentType;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.mock.web.MockMultipartFile;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;

@RestController
@RequestMapping("/ljp")
public class LjpexclusiveController {

    @Autowired
    LjpexclusiveService ljpexclusiveService;
    //搜索
    @GetMapping("/getunion")
    public R getunion(String keyword,Integer userid){
        if(keyword==null){
            keyword="";
        }
        System.out.println(keyword);

        R r=ljpexclusiveService.getunion(keyword,userid);
        return r;

    }
    //搜索历史
    @GetMapping("/getsearchhistory")
    public R getsearchhistory(Integer userid){
        R r=ljpexclusiveService.getsearchhistory(userid);
        return r;
    }
    //限时兑换
    @GetMapping("/gettimeexchange")
    public R gettimeexchange(){
     return null;
    }

    //清空历史记录
    @GetMapping("/dells")
    public R dells(Integer userid){
        R r=ljpexclusiveService.dells(userid);
        return r;
    }
    //垃圾分类详情
    @GetMapping("/getclassxq")
    public R getclassxq(Integer id){
        R r=ljpexclusiveService.getclassxq(id);
        return r;
    }

    //讨论详情详情页面
    @GetMapping("/inittlxq")
    public R inittlxq(Integer id){
        R r=ljpexclusiveService.inittlxq(id);
        return r;
    }
    //精彩评论
    @GetMapping("/getwonderfulcomments")
    public R getwonderfulcomments(Integer id){
        R r=ljpexclusiveService.getwonderfulcomments(id);
        return r;
    }

    //关注讨论
    @GetMapping("/setguanzhu")
    public R setguanzhu(Integer id,Integer discussid){
        R r=ljpexclusiveService.setguanzhu(id,discussid);
        return r;
    }

    //取消关注
    @GetMapping("/delguanzhu")
    public R delguanzhu(Integer id,Integer discussid){
        R r=ljpexclusiveService.delguanzhu(id,discussid);
        return r;
    }

    //关注列表
    @GetMapping("/guanzhutype")
    public R guanzhutype(Integer userid){
        R r=ljpexclusiveService.guanzhutype(userid);
        return r;
    }

    //点赞评论
    @GetMapping("/setdianzan")
    public R setdianzan(Integer userid,Integer commentid){
        R r=ljpexclusiveService.setdianzan(userid,commentid);
        return r;
    }

    //评论
    @GetMapping("/setpl")
    public R setpl(Integer fid,Integer userid,String contents,Integer id){
        System.out.println("父类id"+fid);
        R r=ljpexclusiveService.setpl(fid,userid,contents,id);
        return r;
    }

    //首页数据
    @GetMapping("/getindex")
    public R getindex(){
        R r=ljpexclusiveService.getindex();
        return r;
    }

    //根据讨论类别查询
    @GetMapping("/gettlbytyle")
    public R gettlbytyle(Integer type){
        if(type==null){
            type=0;
        }
        R r=ljpexclusiveService.gettlbytyle(type);
        return r;
    }

    //发布讨论
    @GetMapping("/adddiscuss")
    public R adddiscuss(String title,Integer pltype,String contents,Integer userid){
        R r=ljpexclusiveService.adddiscuss(title,pltype,contents,userid);
        return r;
    }

    //查看签到情况
    @GetMapping("/initsignin")
    public R initsignin(Integer userid,String time){
        R r=ljpexclusiveService.initsignin(userid,time);
        return r;
    }

    //签到
    @GetMapping("/setsignin")
    public R setsignin(Integer userid){
        R r=ljpexclusiveService.setsignin(userid);
        return r;
    }

    //初始化商城页面
    @GetMapping("/initsc")
    public R initsc(Integer userid){
        R r=ljpexclusiveService.initsc(userid);
        return r;
    }

    //热门商品页面
    @GetMapping("/initremen")
    public R initremen(){
        R r=ljpexclusiveService.initremen();
        return r;
    }

    //商品详情
    @GetMapping("/initspxq")
    public R initspxq(Integer commodityid,Integer userid){
        R r=ljpexclusiveService.initspxq(commodityid);
        R r1=ljpexclusiveService.addfootprint(commodityid,userid);
        return r;
    }

    //猜你喜欢
    @GetMapping("/getguesslike")
    public R getguesslike(Integer userid){
        R r=ljpexclusiveService.getguesslike(userid);
        return r;
    }

    //加入购物车
    @GetMapping("/addgwc")
    public R addgwc(Integer userid,Integer commodityid,Integer selectionId,Integer sum,Double price){
        R r=ljpexclusiveService.addgwc(userid,commodityid,selectionId,sum,price);
        return r;
    }

    //收藏商品
    @GetMapping("/addsc")
    public R addsc(Integer userid,Integer commodityid){
        R r=ljpexclusiveService.addsc(userid,commodityid);
        return r;
    }

    //删除商品
    @GetMapping("/delsc")
    public R delsc(Integer userid,Integer commodityid){
        R r=ljpexclusiveService.delsc(userid,commodityid);
        return r;
    }

    //获取用户收藏的商品
    @GetMapping("/getissc")
    public R getissc(Integer userid){
        R r=ljpexclusiveService.getissc(userid);
        return r;
    }

    //生成临时商品订单
    @GetMapping("/addorder")
    public R addorder(Integer userid,Integer commodityid,Integer selectionId,Integer sum,Double price){
        R r=ljpexclusiveService.addorder(userid,commodityid,selectionId,sum,price);
        return r;
    }

//    查询全部门店信息
    @GetMapping("/initmd")
    public R initmd(Integer commodityid,Integer type){
        R r=ljpexclusiveService.initmd(commodityid,type);
        return r;
    }
    //生成临时订单
    @PostMapping("/temporaryorder")
    public R temporaryorder(@RequestBody CommodityorderVo commodityorder){
        System.out.println(commodityorder);
        R r=ljpexclusiveService.temporaryorder(commodityorder);
        return r;
    }

    //创建订单
    @PostMapping("/zhifu")
    public R zhifu(@RequestBody CommodityorderVo commodityorder) throws IOException {
        R r=ljpexclusiveService.zhifu(commodityorder);
        return r;
    }

    //二维码测试
    @GetMapping("/idtest")
    public R idtest() throws IOException {
        R r=ljpexclusiveService.idtest();
        return r;
    }

    //查看购物车
    @GetMapping("/initgwc")
    public R initgwc(Integer userid){
        R r=ljpexclusiveService.initgwc(userid);
        return r;
    }

    @GetMapping("/gwcjs")
    public R gwcjs(Integer scid){
        R r=ljpexclusiveService.gwcjs(scid);
        return r;
    }

    @GetMapping("/delgwc")
    public R delgwc(Integer scid){
        R r=ljpexclusiveService.delgwc(scid);
        return r;
    }

    @GetMapping("/initxsdh")
    public R initxsdh(){
        R r=ljpexclusiveService.initxsdh();
        return r;
    }

    //垃圾分类
    @GetMapping("/initclassfl")
    public R initclassfl(){
        R r=ljpexclusiveService.initclassfl();
        return r;
    }

    @Autowired
    AliOss aliOss;
    @GetMapping("/ttt")
    public void ttt() throws IOException {
        File pdfFile = new File("C:\\Users\\MECHREVO\\Desktop\\11111.png");
        FileInputStream fileInputStream = new FileInputStream(pdfFile);
        MultipartFile multipartFile = new MockMultipartFile(pdfFile.getName(), pdfFile.getName(),
                ContentType.APPLICATION_OCTET_STREAM.toString(), fileInputStream);
        String upload = aliOss.upload(multipartFile);
        System.out.println(upload);
    }

    @GetMapping("/getlj")
    public R getlj(Integer id){
        R r=ljpexclusiveService.getlj(id);

        return r;
    }



}
